#ifndef _NODE_SERVER_H_INCLUDE_
#define _NODE_SERVER_H_INCLUDE_

#include <stdio.h>
#include <dlfcn.h>
#include <time.h>
#include <vector>
#include <unordered_map>  
#include <map>
#include <list>
#include <string>
#include <jsoncpp/json/json.h>

#include "../include/molnet/Network.h"

using namespace network;
using namespace std;

struct tagServerConfig
{
	tagServerConfig():port(0),client(NULL) {}
	tagServerConfig(const char *address,int p,CMolTcpSocketClient *clt):port(p),client(clt) {
		strncpy(ipaddress,address,strlen(address));
	}

	CMolTcpSocketClient *client;
	char ipaddress[32];
	int port;
};

struct tagSubscriber
{
	tagSubscriber():socketid(-1) {}
	tagSubscriber(int si,std::string uid,std::string ssp):
		socketid(si),uniqueid(uid),subscriptions(ssp) {}

	int socketid;
	std::string subscriptions;
	std::string uniqueid;
};

bool LoadServerConfig(void);
void process_child_servers(void);
void public_message(int type,Json::Value &mes);
void unsuscriptions(int socketid,int type=0,std::string scription="");
void suscriptions(int socketid,int type,std::string uniqueid,std::string scription,std::string password);

extern std::unordered_map<std::string,tagServerConfig> m_ServerConfigs;
extern std::unordered_map<std::string,std::map<int,tagSubscriber> > m_Subscribers;
extern std::unordered_map<std::string,std::string> m_SubscribersPwd;

#define IDD_MESSAGE_SUSCRIPTIONS 10000     
#define IDD_MESSAGE_PUBSCRIPTIONS 10001     
#define IDD_MESSAGE_UNPUBSCRIPTIONS 10002   
#define IDD_MESSAGE_CLIENT_ONLINE 10003
#define IDD_MESSAGE_CLIENT_OFFLINE 10004

#endif 